package com.duxiaolie.demobook.service.impl;

import com.duxiaolie.demobook.entity.User;
import com.duxiaolie.demobook.mapper.UserMapper;
import com.duxiaolie.demobook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: WeiYingYu
 * Description: TODO
 * <p>File Created at 2020/10/18</p>
 */
@Service
@Transactional(rollbackFor = Exception.class) // 注解【Transactional】需要设置rollbackFor属性。--新东西
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;  // 奇怪为什么没有找到这个bean呢？我是加了注解的呀...

    /**
     * 查询所有用户
     *
     * @return
     */
    @Override
    @Cacheable(value = "UserCache",key = "'user.getAllUser'")
    public List<User> getAllUser() {
        return userMapper.getAllUser();

    }

    /**
     * 删除用户
     *
     * @param id
     */
    @Override
    @CacheEvict(value = "UserCache",key = "'user.getAllUser'")
    public void del(Integer id) {
        userMapper.del(id);
    }
}
